﻿namespace Game.Web.Module.AccountManager
{
    using Game.Facade;
    using Game.Kernel;
    using Game.Utils;
    using Game.Web.UI;
    using System;
    using System.Data;
    using System.Text;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using Wuqi.Webdiyer;

    public pratical class RecordDrawInfoList : AdminPage
    {
       

        protected void anpPage_PageChanged(object sender, EventArgs e)
        {
            this.BindData();
        }

        private void BindData()
        {
            if (base.aideAccountsFacade.GetAccountInfoByUserID(base.IntParam) != null)
            {
                PagerSet set = base.aideTreasureFacade.GetRecordDrawInfoList(this.anpPage.CurrentPageIndex, this.anpPage.PageSize, this.SearchItems, this.Orderby);
                this.anpPage.RecordCount = set.RecordCount;
                if (set.PageSet.Tables[0].Rows.Count > 0)
                {
                    this.rptDataList.DataSource = set.PageSet;
                    this.rptDataList.DataBind();
                    this.rptDataList.Visible = true;
                    this.litNoData.Visible = false;
                }
                else
                {
                    this.rptDataList.Visible = false;
                    this.litNoData.Visible = true;
                }
            }
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            string text = CtrlHelper.GetText(this.txtStartDate);
            string endDate = CtrlHelper.GetText(this.txtEndDate);
            this.SetCondition(text, endDate);
            this.BindData();
        }

        protected void btnQueryTD_Click(object sender, EventArgs e)
        {
            string str = Fetch.GetTodayTime().Split(new char[] { '$' })[0].ToString();
            string str2 = Fetch.GetTodayTime().Split(new char[] { '$' })[1].ToString();
            CtrlHelper.SetText(this.txtStartDate, Convert.ToDateTime(str).ToString("yyyy-MM-dd"));
            CtrlHelper.SetText(this.txtEndDate, Convert.ToDateTime(str2).ToString("yyyy-MM-dd"));
            this.SetCondition(str, str2);
            this.BindData();
        }

        protected void btnQueryTW_Click(object sender, EventArgs e)
        {
            string str = Fetch.GetWeekTime().Split(new char[] { '$' })[0].ToString();
            string str2 = Fetch.GetWeekTime().Split(new char[] { '$' })[1].ToString();
            CtrlHelper.SetText(this.txtStartDate, Convert.ToDateTime(str).ToString("yyyy-MM-dd"));
            CtrlHelper.SetText(this.txtEndDate, Convert.ToDateTime(str2).ToString("yyyy-MM-dd"));
            this.SetCondition(str, str2);
            this.BindData();
        }

        protected void btnQueryYD_Click(object sender, EventArgs e)
        {
            string str = Fetch.GetYesterdayTime().Split(new char[] { '$' })[0].ToString();
            string str2 = Fetch.GetYesterdayTime().Split(new char[] { '$' })[1].ToString();
            CtrlHelper.SetText(this.txtStartDate, Convert.ToDateTime(str).ToString("yyyy-MM-dd"));
            CtrlHelper.SetText(this.txtEndDate, Convert.ToDateTime(str2).ToString("yyyy-MM-dd"));
            this.SetCondition(str, str2);
            this.BindData();
        }

        protected void btnQueryYW_Click(object sender, EventArgs e)
        {
            string str = Fetch.GetLastWeekTime().Split(new char[] { '$' })[0].ToString();
            string str2 = Fetch.GetLastWeekTime().Split(new char[] { '$' })[1].ToString();
            CtrlHelper.SetText(this.txtStartDate, Convert.ToDateTime(str).ToString("yyyy-MM-dd"));
            CtrlHelper.SetText(this.txtEndDate, Convert.ToDateTime(str2).ToString("yyyy-MM-dd"));
            this.SetCondition(str, str2);
            this.BindData();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (base.Header != null)
            {
                base.Title = this.StrTitle;
            }
            if (!base.IsPostBack)
            {
                this.txtStartDate.Text = DateTime.Now.ToString("yyyy-MM-") + "01";
                this.txtEndDate.Text = DateTime.Now.ToString("yyyy-MM-dd");
            }
        }

        protected void rptDataList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                DataRowView dataItem = (DataRowView) e.Item.DataItem;
                PagerSet set = base.aideTreasureFacade.GetRecordDrawScoreList(1, 0x3e8, string.Format("WHERE DrawID={0}", dataItem["DrawID"].ToString()), "ORDER BY DrawID DESC");
                if (set.PageSet.Tables.Count > 0)
                {
                    Repeater repeater = (Repeater) e.Item.FindControl("rptSubData");
                    if (repeater != null)
                    {
                        repeater.DataSource = set.PageSet;
                        repeater.DataBind();
                    }
                }
            }
        }

        private void SetCondition(string startDate, string endDate)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(" WHERE DrawID IN (SELECT DrawID FROM  RecordDrawScore WHERE UserID={0})", base.IntParam.ToString());
            if (!string.IsNullOrEmpty(startDate))
            {
                builder.AppendFormat(" AND ConcludeTime >= '{0}' ", startDate);
            }
            if (!string.IsNullOrEmpty(endDate))
            {
                builder.AppendFormat(" AND ConcludeTime < '{0}'", Convert.ToDateTime(endDate).AddDays(1.0).ToString("yyyy-MM-dd"));
            }
            this.ViewState["SearchItems"] = builder.ToString();
        }

        public string Orderby
        {
            get
            {
                if (this.ViewState["Orderby"] == null)
                {
                    this.ViewState["Orderby"] = "ORDER BY DrawID DESC";
                }
                return (string) this.ViewState["Orderby"];
            }
            set
            {
                this.ViewState["Orderby"] = value;
            }
        }

        public string SearchItems
        {
            get
            {
                if (this.ViewState["SearchItems"] == null)
                {
                    StringBuilder builder = new StringBuilder();
                    builder.Append(string.Format(" WHERE DrawID IN (SELECT DrawID FROM  RecordDrawScore WHERE UserID={0})", base.IntParam.ToString()));
                    this.ViewState["SearchItems"] = builder.ToString();
                }
                return (string) this.ViewState["SearchItems"];
            }
            set
            {
                this.ViewState["SearchItems"] = value;
            }
        }

        public string StrTitle
        {
            get
            {
                return ("玩家-" + base.GetAccounts(base.IntParam) + "-游戏记录");
            }
        }
    }
}

